import Vue from 'vue'
import Vuex from 'vuex'
import createPersistedState from 'vuex-persistedstate'
Vue.use(Vuex)
import state from '@/store/state.js'
import actions from '@/store/action.js'
import getters from '@/store/getters.js'
import mutations from '@/store/mutations.js'
const Store = new Vuex.Store({
	state,
	actions:{
		...actions,
		async fetchUserInfo({
			commit,state
		}) {
			
			try {
				 const userId = state.User.userId;
				// 调用获取用户信息的接口
				const response = await Vue.prototype.$request.get(`/CatUser/${userId}`,{}); // 替换为实际的获取用户信息的接口
		        console.log(response.data,'uuuuuuuuuuuuuuuuuuu');
				// 更新用户信息到 Vuex
				commit('SET_USER_INFO', response.data.user); // 假设接口返回的用户信息在 response.data 中
			} catch (error) {
				console.error('获取用户信息失败', error);
			}
		},
	},
	getters,
	mutations,
	plugins: [
		createPersistedState({
			storage: {
				getItem: key => wx.getStorageSync(key),
				setItem: (key, value) => wx.setStorageSync(key, value),
				removeItem: key => {}
			}
		})
	],
})
export default Store
